<?php
namespace app\controller;

use think\Request;
use app\controller\Base;
use app\common\UtilService;
use app\model\EaWxCompany;
use app\model\EaWxSite;
use app\model\EaWxPrograms;

class Company extends Base
{
    /**
     * [index 首页]
     * @since  2025-06-04
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function index(Request $request)
    {
    	$param = UtilService::getMore([
    		['page', 1],
    		['pageSize', 10],
    	]);

        $list = EaWxCompany::getCompanyList($param);
        // dump($list);exit;
        
        # 最新加入站点
        $new_site = EaWxSite::field('id, title, pics, descs')->where('status', 1)->order('dates DESC, id DESC')->limit(17)->cache(600)->select()->toArray();

        # 热门小程序
        // $new_programs = EaWxPrograms::field('*')->where('status', 1)->order('views DESC')->limit(10)->cache(600)->select()->toArray();
    
        return view('index', compact('list', 'new_site'));
    }

    /**
     * [info 详细]
     * @since  2025-06-11
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function info(Request $request)
    {
    	$param = UtilService::getMore([
            ['id', ''],
    		['title', ''],
    	]);

        $info = EaWxCompany::getCompanyInfo($param);

        # 最新加入站点
        $new_site = EaWxSite::field('id, title, pics, descs')->where('status', 1)->order('dates DESC, id DESC')->limit(17)->cache(600)->select()->toArray();

        # 公司旗下网站
        $cp_site_list = EaWxSite::field('id, title, pics')
            ->where('status', 1)
            ->whereLike('icp_name', "%{$info['title']}%")
            ->cache(600)
            ->select()
            ->toArray();

            // dump($cp_site_list);exit;

        return view('info', compact('info', 'new_site', 'cp_site_list'));
    }
}
